package Collection;

import demo1.Student1;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class IteratorDemo2 {
    public static void main(String[] args) {
        //创建集合类对象
        Collection coll=new ArrayList();
        //向集合中添加数据
        coll.add(new Student1("张三",19));
        //遍历取出集合中的数据
        for (Iterator it = coll.iterator(); it.hasNext();) {
            /*
             * 如果自定义Student类中不复写toString()函数那么就会输出一串内存地址
             * cn.itcast.sh.demo.Student@6d9dd520
             */
            System.out.println(it.next());
        }
    }
}
